package com.zhlb.zfba.modules.per.service;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhlb.zfba.common.utils.DateUtil;
import com.zhlb.zfba.common.utils.IdGen;
import com.zhlb.zfba.modules.card.bean.CardRegInfo;
import com.zhlb.zfba.modules.card.service.CardRegInfoService;
import com.zhlb.zfba.modules.per.bean.GoodsInfo;
import com.zhlb.zfba.modules.per.bean.PoliceInfo;
import com.zhlb.zfba.modules.per.bean.SuspectInfo;
import com.zhlb.zfba.modules.per.dao.GoodsInfoDao;
import com.zhlb.zfba.modules.per.dao.PoliceInfoDao;
import com.zhlb.zfba.modules.per.dao.SuspectInfoDao;

@Service
@Transactional(readOnly = true)
public class GoodsInfoService {
	@Autowired 
	GoodsInfoDao goodsInfoDao;
	@Autowired
	CardRegInfoService cardRegInfoService;
	public GoodsInfo get(String id) {
		return goodsInfoDao.get(id);
	}
	
	public List<GoodsInfo> findList(GoodsInfo goodsInfo) {
		return goodsInfoDao.findList(goodsInfo);
	}

	@Transactional(readOnly = false)
	public void save(GoodsInfo goodsInfo) {
		if(StringUtils.isBlank(goodsInfo.getGoodsGUID())){
			goodsInfo.setGoodsGUID(IdGen.uuid());
//			goodsInfo.setInTime(DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss"));
			goodsInfoDao.insert(goodsInfo);
			
		}else{
			GoodsInfo updateEntity=this.get(goodsInfo.getGoodsGUID());
			//自封袋号
			//储物柜号
			//接收人
			//接时间
			//物品内容
			goodsInfoDao.update(updateEntity);
		 }
	}
	
	@Transactional(readOnly = false)
	public void delete(String ids) {
		String[] idArr=null;
		if(StringUtils.isNotBlank(ids)){
			idArr=ids.split(",");
			for(String id:idArr){
				goodsInfoDao.delete(id);
			}
		}
		
	}
	@Transactional(readOnly = false)
	public void updateIsLeave(SuspectInfo suspectInfo){
		suspectInfo.setIsLeave("1");
		suspectInfo.setLeaveTime(DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss"));
		//suspectInfoDao.updateIsLeaveOfSuspectInfo(suspectInfo);
	}
}
